home *** CD-ROM | disk | FTP | other *** search
/ Joystick Magazine 1996 May / cd joy 71No13.iso / pc / demos / eurosoc / source / euro_mem.cpp < prev    next >
C/C++ Source or Header  |  1996-03-14  |  6KB  |  233 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. #include "eurodefs.h"
  6. #include "euro_fxd.h"
  7. #include "euro_sym.h"
  8. #include "euro_def.h"
  9. #include "euro_var.h"
  10. #include "mallocx.h"
  11.  
  12. //********************************************************************************************************************************
  13.  
  14. void    DeAllocateMemory( BYTE* MemAlloc )
  15.     {
  16.         if ( MemAlloc != 0 ) 
  17.             freex( MemAlloc );
  18.  
  19.         if ( EUROverbose != 0 )
  20.         {
  21.             printf ("˛ Memory check: %d\n",get_mem_info() );
  22.              fflush(stdout);
  23.         }
  24.     }
  25.  
  26. //********************************************************************************************************************************
  27.  
  28. void    Euro96_MemoryInitialise()
  29.     {
  30.         TexturePageMemHandle    =    0;
  31.         TextStringMemHandle    =    0;
  32.     }
  33.  
  34. //********************************************************************************************************************************
  35.  
  36. void    AllocateDisplayBuffers()
  37.     {
  38.         EuroPseudoBuffer = (BYTE *) mallocx( 307200);
  39.  
  40.         if ( EuroPseudoBuffer == 0 )
  41.         {
  42.             printf    ("˛ Unable to allocate memory for Pseudo buffer.\n");
  43.              fflush(stdout);
  44.         }
  45.  
  46.         else
  47.         {
  48.             if ( EUROverbose != 0 )
  49.             {
  50.                 printf ("˛ Memory allocated for Pseudo buffer.\n");
  51.                  fflush(stdout);
  52.                 printf ("˛ Memory check: %d\n",get_mem_info() );
  53.                  fflush(stdout);
  54.             }
  55.         }
  56.  
  57.         EuroBackgroundBuffer = (BYTE *) mallocx( 307200);
  58.  
  59.         if ( EuroBackgroundBuffer == 0 )
  60.         {
  61.             printf    ("˛ Unable to allocate memory for Background buffer.\n");
  62.              fflush(stdout);
  63.         }
  64.  
  65.         else
  66.  
  67.         {
  68.             if ( EUROverbose != 0 )
  69.             {
  70.                 printf    ("˛ Memory allocated for Background buffer.\n");
  71.                  fflush(stdout);
  72.                 printf ("˛ Memory check: %d\n",get_mem_info() );
  73.                  fflush(stdout);
  74.             }
  75.         }
  76.     }
  77.  
  78. //********************************************************************************************************************************
  79.  
  80. void    DeAllocateDisplayBuffers()
  81.     {
  82.         if ( EuroBackgroundBuffer != 0 )
  83.         {
  84.             DeAllocateMemory(EuroBackgroundBuffer);
  85.             if ( EUROverbose != 0 )
  86.             {
  87.                       printf ("˛ Memory for Background buffer DeAllocated.\n");
  88.                  printf ("˛ Memory check: %d\n",get_mem_info() );
  89.                  fflush(stdout);
  90.             }
  91.         }
  92.  
  93.         else
  94.  
  95.         {
  96.                   printf    ("˛ ERROR.. Unable to deAllocate memory for Background Buffer (This could cause a crash).\n");
  97.             fflush(stdout);
  98.          }
  99.         
  100.  
  101.         if ( EuroPseudoBuffer != 0 )
  102.         {
  103.             DeAllocateMemory(EuroPseudoBuffer);
  104.             if ( EUROverbose != 0 )
  105.             {
  106.                       printf ("˛ Memory for Pseudo buffer DeAllocated.\n");
  107.                 fflush(stdout);
  108.                  printf ("˛ Memory check: %d\n",get_mem_info() );
  109.                 fflush(stdout);
  110.             }
  111.         }
  112.  
  113.         else
  114.  
  115.         {
  116.                   printf    ("˛ ERROR.. Unable to deAllocate memory for Pseudo Buffer (This could cause a crash).\n");
  117.             fflush(stdout);
  118.         }
  119.     }
  120.  
  121. //********************************************************************************************************************************
  122.  
  123. BYTE*    AllocateTexturePageMemory( unsigned char NoOfTexturePages, texture_info *texture )
  124.     {
  125.         unsigned int size = texture->page_width*texture->page_height*NoOfTexturePages;
  126.         TexturePages      = (BYTE *) mallocx( size );
  127.         
  128.         if ( TexturePages==0 )
  129.         {
  130.                   printf    ("˛ ERROR.. Unable to reserve memory for Texture Pages (This could cause a crash).\n");
  131.             fflush(stdout);
  132.              TexturePagesAvailable    =    0;
  133.         }
  134.         
  135.         else
  136.  
  137.              TexturePagesAvailable    =    NoOfTexturePages;
  138.  
  139.             if ( EUROverbose != 0 )
  140.             {
  141.                       printf ("˛ Memory allocated for Texture Pages.\n");
  142.                 fflush(stdout);
  143.                  printf ("˛ Memory check: %d\n",get_mem_info() );
  144.                 fflush(stdout);
  145.             }
  146.  
  147.         return ( TexturePages );
  148.     }
  149.  
  150. //********************************************************************************************************************************
  151.  
  152. void    DeAllocateTexturePages()
  153.     {
  154.         if ( TexturePageMemHandle != 0 )
  155.         {
  156.             DeAllocateMemory(TexturePageMemHandle);
  157.             if ( EUROverbose != 0 )
  158.             {
  159.                       printf ("˛ Memory for Texture Pages DeAllocated.\n");
  160.                 fflush(stdout);
  161.                  printf ("˛ Memory check: %d\n",get_mem_info() );
  162.                 fflush(stdout);
  163.             }
  164.         }
  165.  
  166.         else    
  167.         
  168.         {
  169.                   printf    ("˛ ERROR.. Unable to deAllocate memory for Texture Pages (This could cause a crash).\n");
  170.              fflush(stdout);
  171.         }
  172.     }
  173.  
  174. //********************************************************************************************************************************
  175.  
  176. BYTE*    AllocateTextStringMemory()
  177.     {
  178.         TextStrings  = (BYTE *) mallocx( TEXT_STRING_BUFFER_LEN );
  179.         
  180.         if ( TextStrings==0 )
  181.         {
  182.             printf    ("˛ Unable to allocate memory for Text buffer.\n");
  183.              fflush(stdout);
  184.         }
  185.         else
  186.         {
  187.             printf    ("˛ Memory allocated for Text buffer.\n");
  188.              fflush(stdout);
  189.  
  190.             {             
  191.                 if ( EUROverbose != 0 )
  192.                      printf ("˛ Memory check: %d\n",get_mem_info() );
  193.                     fflush(stdout);
  194.             }
  195.         }
  196.  
  197.         return ( TextStrings );
  198.     }
  199.  
  200. //********************************************************************************************************************************
  201. //
  202. //int DisplayFree()
  203. //    {
  204. //        int    M8;
  205. //        int buff[20];
  206. //        union    REGS regs;
  207. //        struct SREGS sregs;
  208. //
  209. //        memset(&sregs,0,sizeof(sregs));                 //clr sregs
  210. //        regs.x.eax=0x500;                               //DPMI get free mem info
  211. //        sregs.es=FP_SEG(buff);                          //Gets SELECTOR in fact.
  212. //        regs.x.edi=FP_OFF(buff);                        //offset from selector.
  213. //        int386x(0x31,®s,®s,&sregs);               //Get free memory info
  214. //
  215. //        M8=( (buff[7]*4096) >= MEM8 );
  216. //
  217. //        if (setup.verbose!=0)
  218. //        {
  219. //            printf("\nLargest block: %d\n",buff[0]);
  220. //            printf("Total free   : %d\n\n",buff[7]*4096);
  221. //            if (M8)
  222. //                puts("Initialising 8 meg game");
  223. //            else
  224. //            {
  225. //                puts("Initialising 4 meg game");
  226. //                printf("Need to free %d more bytes to run 8 meg version\n",MEM8-(buff[7]*4096) );
  227. //            }
  228. //        }
  229. //        return    (M8);
  230. //    }
  231. //
  232. //********************************************************************************************************************************
  233.